package org.ceteca.explica.client;

import org.ceteca.javaglade.toolkit.swt.StatusBar;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;

public class AutoUpdateInitProgressBarOperation implements Runnable {
	private Display display;
	private ProgressBar progressBar;
	private StatusBar statusBar;
	private String statusText;
	private boolean isEnabled;
	
	public AutoUpdateInitProgressBarOperation(Display display, ProgressBar progressBar, StatusBar statusBar, String statusText) {
		this.progressBar = progressBar;
		this.statusBar = statusBar;
		this.statusText = statusText;
		this.display = display;
		this.isEnabled = true;
	}
	
	public void run() {
		if (progressBar.isDisposed()) return;
		while(this.isEnabled) {
			System.out.println("¡¡¡¡¡¡¡¡¡¡¡¡¡ isEnable? " + this.isEnabled + " !!!!!!!!!!");
			try {
				Thread.sleep(1000);
			} catch(InterruptedException e){
			}
			
	        // Increment the progress bar
			this.display.asyncExec(new UpdateInitProgressBarOperation(this.progressBar, this.statusBar, this.statusText));
		}
	}
	
	public void stop() {
		System.out.println("¡¡¡¡¡¡¡¡¡¡¡¡¡ UNSET ISENABLE !!!!!!!!!!");
		this.isEnabled = false;
	}
}